/**
 * Created by shidaiapp on 2017/9/29.
 */

import actionUrls from "../../../../api/ApiUrls"
import ApiBase from "../../../../api/moudles/ApiBase"
/**
 * 初始化
 * @param self
 * @param tiyData
 */
export const init = (self, tiyData) => {
  //resetForm(self, tiyData);
  tiyData.tPage.total = 1;
  tiyData.tPage.startIndex = 0;
  tiyData.tPage.stepNumber = 40;
  tiyData.tPage.currentPage = 1;
  tiyData.tParams.searchParams.categoryCode = "";
  tiyData.tParams.searchParams.categoryLevel = 0;
  tiyData.tParams.searchParams.startCreatedate = "";
  tiyData.tParams.searchParams.endCreatedate = "";
  tiyData.tParams.searchParams.productCode = "";
  tiyData.tParams.detailParams.page.total = 1;
  tiyData.tParams.detailParams.page.startIndex = 0;
  tiyData.tParams.detailParams.page.stepNumber = 40;
  tiyData.tParams.detailParams.page.currentPage = 1;
  tiyData.tStatus.modalDetail.title = "";
  tiyData.tStatus.modalDetail.isShow = false;
  tiyData.tStatus.uploadXml.isUploading = false;


};

/**
 * 从服务器请求列表
 * @param self
 * @param tiyData
 * @returns {Array}
 */
export const webList = (self, tiyData) => {
  self.$Spin.show();
  self.$apiAnalysis.productDetailList({
    "pageSize": tiyData.tPage.stepNumber,
    "pageNum": tiyData.tPage.currentPage,
    "startCreatedate": tiyData.tParams.searchParams.startCreatedate,
    "endCreatedate": tiyData.tParams.searchParams.endCreatedate,
    "productCode": tiyData.tParams.searchParams.productCode,
    "categoryCode": tiyData.tParams.searchParams.categoryCode,
    "categoryLevel": tiyData.tParams.searchParams.categoryLevel,
  }).then(function (response) {
    self.$Spin.hide();
    if (response.success) {
      tiyData.tData.productVisitList.length = 0;
      let productVisitPage = response.result;
      tiyData.tPage.total = productVisitPage.total;
      tiyData.tPage.stepNumber = productVisitPage.pageSize;
      productVisitPage.list.forEach(
        function (item) {
          tiyData.tData.productVisitList.push(item);
        }
      );
      if (0 == tiyData.tData.productVisitList.length) {
        tiyData.tData.productVisitList.splice(0, tiyData.tData.productVisitList.length);
      }
    } else {
      self.$Message.error(response.errorMessage);
    }
  });
};

/**
 * 从服务器请求列表
 * @param self
 * @param tiyData
 * @returns {Array}
 */
export const webProductDetail = (self, tiyData,product) => {
  self.$Spin.show();
  self.$apiAnalysis.productDetail({
    "pageSize": tiyData.tParams.detailParams.page.stepNumber,
    "pageNum": tiyData.tParams.detailParams.page.currentPage,
    "productId": product.productId,
  }).then(function (response) {
    self.$Spin.hide();
    if (response.success) {
      tiyData.tData.productDetailList.length = 0;
      let productDetailPage = response.result;
      tiyData.tParams.detailParams.page.total = productDetailPage.total;
      tiyData.tParams.detailParams.page.stepNumber = productDetailPage.pageSize;
      productDetailPage.list.forEach(
        function (item) {
          tiyData.tData.productDetailList.push(item);
        }
      );
      if (0 == tiyData.tData.productDetailList.length) {
        tiyData.tData.productDetailList.splice(0, tiyData.tData.productDetailList.length);
      }
      tiyData.tStatus.modalDetail.title = "产品 "+ product.productCode + " 的访问记录";
      tiyData.tStatus.modalDetail.isShow = true;
    } else {
      self.$Message.error(response.errorMessage);
    }
  });

};
